package com.papa91.activity;
import java.io.File;
import java.io.IOException;



import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.JsonObject;
import com.join.mgps.aidl.AIDLService;
import com.join.mgps.aidl.R;
import com.papa91.banner.BannerInfo;
import com.papa91.common.BaseAppConfig;
import com.papa91.common.MyJson;
import com.papa91.paay.PaayReceiver;
import com.papa91.paay.PayCenter;
import com.papa91.paay.PayListener;
import com.papa91.paay.PayResponse;
import com.papa91.paay.PayResponseData;
import com.papa91.utils.AsyncImageLoader;
import com.papa91.utils.DownLoadFile;
import com.papa91.utils.HttpFinishInterface;
import com.papa91.utils.HttpUtils;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

@SuppressLint("NewApi")
public class EmuBaseActivity extends Cocos2dxActivity{
	public static final String appPackName_mgsim = "com.join.android.app.mgsim";//正式版
	public static final String appPackName_mha = "com.join.android.app.mgsim.mha";//AB 版
	public static final String appPackName_aso4 = "com.papa91.fc.aso4";
	public static String appPackName = appPackName_mgsim;
	private static final String LOG_TAG = "EmuBaseActivity";
	private boolean appCodeIsBigger160 = false;
	private static EmuBaseActivity baseActivity;
	private static int payType = 0;
	public static final int SELECT_SP = 1;
	public static final int SELECT_COIN = 2;
	public static final int PAY_SP = 3;
	public static final int PAY_COIN = 4;
	public static final int SELECT_CHEAT = 5;
	public static final int PAY_CHEAT = 6;
	public static final int PAY_JOIN = 7;
	public static final int SELECT_JOIN = 8;
	public static final int SHOW_AD = 9;
	public static final int CLOSE_AD = 10;
	public static final int RAISE_VIP = 11;
	public static final int COMPLAIN_PLAYER = 12;
	protected static final String ON_NETWORK_ERROR_MSG = "您的网络有点差，请重试";
	protected static final String ON_TOKER_LOST_MSG = "验证失败请重新登录";

	public static int[] keyVaule = { 0, 0, 0, 0 };
	public static String romName;
	public static String screenMOde = "1";
	public static String enableAudio = "1";
	public static String vibriorMode = "1";
	public static String version = "1.5.0";
	public static int fid = 0;
	protected PaayReceiver paayReceiver;
	public static String romPath = null; // {"userId":"1","gameId":"23243431","version":"1.0","roomid":"1001","porder":0}
	public static String ugcPath = null;
	protected static int startMode = 0;
	public static String server_ip; // "serverIP"
	protected static String server_port = "5369";
	public static String UserID = "0";
	public static String GameID = "0";
	public static String Version = "0";
	public static String RoomID = "0";
	public static long startTIme = 0;
	public static int spLock = 0;
	public static String token = "0";
	private static String UPDATA_APP_TOAST = "请先将啪啪模拟器升级1.6版本";
	protected static AIDLService aidlService;
	public static final int BBK_IQOO = 1; // vivo and gionee phone use this
	public static final int GIONEE_SOFTMANAGER = 2;
	private static final String PAPA_EMU_INTENT_EXTRA_ACTION_FROM = "PAPA_EMU_INTENT_EXTRA_ACTION_FROM";
	private static final int TO_PREFECTURE_KEY = 100;
	private static final int EXIT_AD_KEY = 101;
	private static int systemSettingType = 0;
	protected String onLoadBannerId;
	protected String onMenuOpenBannerId;
	protected String onExitBannerId;
	protected String AD_appId;
	protected List<BannerInfo> bannerInfos = new ArrayList<BannerInfo>();
	protected FrameLayout adExitRootView;
	protected int m_SVIP = 0;
	protected int m_VIP = 0;
	//退出广告相关属性
	public static  String DEVICE_VERSION = "";//=  Build.VERSION.CODENAME;
	public static  String DEVICE_ID = "";
	public static String httpKeySign = "";
	public static String ExitAdImageFilePath= "";
	public static boolean hasAd = false;
	public boolean onAdShwoIsCloseMine = false;
	String messData = ""; //服务器返回的json
	private String link_type;
	private String jump_type;
	private String link_type_val;
	private String crc_link_type_val;
	private String tpl_type;
	private int APP_Version = 0;
	public boolean allowPeripheralJoin = true;
	public static final int LIKT_TYPE_TO_HTML5 = 4; //调HTML 5页面
	 static String actionEmuintent = "com.wufun.intent.activity.view.action.emuintent";//fufun
	static {
		try {
			System.loadLibrary("YvImSdk");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void showAdFromType(int type) {
		for (int s = 0; s < bannerInfos.size(); s++) {
			if (bannerInfos.get(s).getType() == type) {
				bannerInfos.get(s).showAd();
				return;
			}
		}

	}
	
	public class PlayTimeReceiver extends BroadcastReceiver {
	    public PlayTimeReceiver() {
	    }

		@Override
		public void onReceive(Context arg0, Intent arg1) {
			// TODO Auto-generated method stub
						
			UserID = arg1.getExtras().getString("uid");
			token = arg1.getExtras().getString("token");
			// int cheat = intent.getExtras().getInt("sp");
			JsonObject json = new JsonObject();
			json.addProperty("uid", UserID);
			json.addProperty("token", token);

			requestOnsign(json.toString());
			
		}
	}
	
	PlayTimeReceiver playTimeReceiver;

	public void closeAdFromType(int type) {
		for (int s = 0; s < bannerInfos.size(); s++) {
			if (bannerInfos.get(s).getType() == type) {
				bannerInfos.get(s).closeAd();
				return;
			}
		}

	}

	// 打点
	private static ServiceConnection serviceConnection = new ServiceConnection() {

		public void onServiceConnected(ComponentName name, IBinder service) {
			// 获得服务对象
			aidlService = AIDLService.Stub.asInterface(service);
			try {
				startTIme = System.currentTimeMillis();
				if (startMode == BaseAppConfig.START_MODE_RESTART)
					aidlService.gameStart15(GameID, UserID);

				else if (startMode == BaseAppConfig.START_MODE_NETCLIENT
						|| startMode == BaseAppConfig.START_MODE_NETSERVER)
					aidlService.gameStartBattle15(GameID, UserID);
				else {
					aidlService.gameStart160(GameID, UserID, startMode);
				}
			} catch (RemoteException e) {
				e.printStackTrace();
			}
		}

		public void onServiceDisconnected(ComponentName name) {
			Log.e("startplayTime","aidlService is disConnected. " );
		}
	};

	public static void bindService() {
				baseActivity.bindService(new Intent("com.papa.mgsim.wufun.aidl.service"), serviceConnection,
				Context.BIND_AUTO_CREATE);
	}

	protected static Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				
					baseActivity.startAPPActivity();
				
				break;
			case 1:
				baseActivity.selectSpAndCheat(payType);
				break;
			case 3:
				baseActivity.getSystemPaste();
				break;
			case 4:
				baseActivity.startBBK_GOINEE_sysAPP();
				break;
			case SHOW_AD:
				baseActivity.showAdFromType(msg.arg1);
				break;
			case CLOSE_AD:
				baseActivity.closeAdFromType(msg.arg1);
				break;
			case RAISE_VIP:
				baseActivity.raseVipToMgsim(msg.arg1);
				break;
			case TO_PREFECTURE_KEY:
				baseActivity.startPrefecture(msg.arg1);
				break;
			case EXIT_AD_KEY:
				baseActivity.startAdActivity(msg.arg1,msg.arg2);
				break;
			case COMPLAIN_PLAYER:
				baseActivity.complainMsg(msg.arg1,msg.arg2);
				break;
			default:
				break;
			}

			super.handleMessage(msg);
		}

	};


	protected static native void requestOnsign(String json);
	
	protected static native void requestOnInquiry(String json);

	// protected static native void setPasteForCheat(byte[] bytes);
	protected static native void setPasteForCheat(String bytes);

	protected static native void requestOnPay(String json);

	protected static native void setVipType(int vip, int sVip);

	
	
	

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		 //设置屏幕常亮
		baseActivity = this;
		initSign();
		
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		
		super.onCreate(savedInstanceState);
		adExitRootView = new FrameLayout(this);
		FrameLayout.LayoutParams frameLayout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		mFrameLayout.addView(adExitRootView, frameLayout);

		appCodeIsBigger160 = findAppVersionTo16();
		com.yunva.im.sdk.lib.YvLoginInit.initApplicationOnCreate(this.getApplication(), "1000153");
		bindService();

		// initRecord();
		paayReceiver = new PaayReceiver() {
			@Override
			public void onReceive(Context context, Intent intent) {
				// TODO Auto-generated method stub
				UserID = intent.getExtras().getString("uid");
				token = intent.getExtras().getString("token");
				int sp = intent.getExtras().getInt("sp");
				// int cheat = intent.getExtras().getInt("sp");
				if (sp == 2) {
					JsonObject json = new JsonObject();
					json.addProperty("isbuy", true);
					json.addProperty("type", payType);
					json.addProperty("data", "already");

					requestOnInquiry(json.toString());

					return;
				}
				selectCondition(payType);
			}
		};
		
		playTimeReceiver = new PlayTimeReceiver();
		
		registerReceiver(playTimeReceiver, new IntentFilter("com.join.android.app.mgsim.wufun.broadcast.action_login_success"));
		
		registerReceiver(paayReceiver, new IntentFilter(PayCenter.ACTION_LOGIN_SUCCESS));

		MyReceiver mu = new MyReceiver();
		IntentFilter counterActionFilter = new IntentFilter(
				"com.join.android.app.mgsim.broadcast.action_raise_vip_success");
		registerReceiver(mu, counterActionFilter);
		//testThread();
		//
		// Intent intent1 = new
		// Intent("com.join.android.app.mgsim.broadcast.action_raise_vip_success");
		// this.sendBroadcast(intent1);
		//

	}

	class MyReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {

			token = intent.getExtras().getString("token");
			int vip = intent.getExtras().getInt("vipLevel");
			int svip = intent.getExtras().getInt("sVipLevel");
			UserID = intent.getExtras().getString("uid");
			setVipType(vip, svip);

		}
	}

	@Override
	protected void onStart() {
		if (isFirstReame(GameID)) {
			modifyRecordInfo(ugcPath, false, false);
			modifyRecordInfo(ugcPath, true, false);
			modifyRecordInfo(ugcPath, false, true);
			setFirestReame(GameID);
		} // TODO Auto-generated method stub
		super.onStart();
	}

	public static void setAdVisible(int type, int isVisible)// type is on
															// loading or select
															// menu or
															// exit-----isVisible
															// 1 true other
															// false
	{
		if (isVisible == 1) {
			Message childMsg = handler.obtainMessage();
			childMsg.what = SHOW_AD;
			childMsg.arg1 = type;
			handler.sendMessage(childMsg);
		} else {
			Message childMsg = handler.obtainMessage();
			childMsg.what = CLOSE_AD;
			childMsg.arg1 = type;
			handler.sendMessage(childMsg);
		}

	}

	public static void sign() {
		Intent mIntent = new Intent();
		mIntent.putExtra("intentFrom",5);
	    ComponentName comp = new ComponentName("com.join.android.app.mgsim.wufun", "com.join.mgps.activity.MyAccountLoginActivity_");
	    mIntent.setComponent(comp);
		mIntent.setAction(Intent.ACTION_VIEW);
		mIntent.setAction("android.intent.action.VIEW");
		baseActivity.startActivity(mIntent);
	}
	
	public static void StartcomplainMsg(String _link_type,String _jump_type,String _link_type_val,String _crc_link_type_val,String _tpl_type)
	{
		
		Log.e("StartcomplainMsg", "StartcomplainMsg---->");
		//http://testanv3frapi.papa91.com/lobby/report?   测试环境
		//"http://anv3frapi.papa91.com/lobby/report?";    //正式环境
		 Intent intent = new Intent();
	     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	     intent.setAction(actionEmuintent);
	  //   intent.setAction("com.papa.intent.activity.view.action.emuintent");
	     intent.addCategory(Intent.CATEGORY_DEFAULT);// 应用过滤条件
	     
	     MyJson json = new MyJson();
	     try {
	    	 json.put("link_type", _link_type);
		     json.put("jump_type", _jump_type);
		     json.put("link_type_val", _link_type_val);
		     json.put("crc_link_type_val", _crc_link_type_val);
		     json.put("tpl_type", _tpl_type); 
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	     intent.putExtra("intentDataJson",json.toString());
	     baseActivity.startActivity(intent);
	   	 
	}


	 public void complainMsg(int uuid,int self_uuid)
	{
		//http://testanv3frapi.papa91.com/lobby/report?   测试环境
		//"http://anv3frapi.papa91.com/lobby/report?";    //正式环境
			link_type = LIKT_TYPE_TO_HTML5+"";
			link_type_val ="http://anv3frapi.papa91.com/lobby/report?"+"report_uid="+self_uuid+"&reported_uid="+uuid;
		 Intent intent = new Intent();
	     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	  

	intent.setAction(actionEmuintent);
	  //   intent.setAction("com.papa.intent.activity.view.action.emuintent");
	     intent.addCategory(Intent.CATEGORY_DEFAULT);// 应用过滤条件
	     
	    MyJson json = new MyJson();
	     try {
			json.put("link_type", link_type);
		     json.put("jump_type", jump_type);
		     json.put("link_type_val", link_type_val);
		  /*   json.put("crc_link_type_val", crc_link_type_val);
		     json.put("tpl_type", tpl_type); */
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	     intent.putExtra("intentDataJson",json.toString());
	     this.startActivity(intent);
	   	 
	}
	
	public static void selectCondition(int type) {
		payType = type;
		handler.sendEmptyMessage(1);
	}

	public static void payCondition(int type) {
		payType = type;
		handler.sendEmptyMessage(2);
	}

	public static void startForumsActivity() {
		handler.sendEmptyMessage(0);
	}
	public static void startForumsActivityForAd(int type,int id) {
		Message childMsg = handler.obtainMessage();
		childMsg.what = EXIT_AD_KEY;
		childMsg.arg1 = type;
		childMsg.arg2 = id;
		handler.sendMessage(childMsg);
	}
	
	public static void startplayTime(int time) {
		try {
			
			Log.e("startplayTime","startplayTime1 " + time);
			if(aidlService != null){
				aidlService.playTime(GameID, UserID,(long)time);
			}else{
				Log.e("startplayTime","aidlService is null. " );
			}
			
			
			Log.e("startplayTime","startplayTime2 " + time);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			Log.e("startplayTime","startplayTime3 " + time);
			e.printStackTrace();
		}
	}
	
	public static void toPrefecture(int p_id)
	{
		Message childMsg = handler.obtainMessage();
		childMsg.what = TO_PREFECTURE_KEY;
		childMsg.arg1 = p_id;
		handler.sendMessage(childMsg);
	}
	PayListener payListener = new PayListener() {
		@Override
		public void onResult(PayResponse payResponse) {
			String msg;
			JsonObject json;
			String errorMsg;
			json = new JsonObject();
			if (null == payResponse) {
				// isBuy = false;
				json.addProperty("isbuy", false);
				requestOnInquiry(json.toString());
				return;
			}

			if (payResponse.getError() == -1) {

				msg = ON_NETWORK_ERROR_MSG;
				json.addProperty("type", payType);
				json.addProperty("data", msg);
				json.addProperty("isbuy", false);
				json.addProperty("errorMsg", ON_NETWORK_ERROR_MSG);
				requestOnPay(json.toString());
				return;
			}

			PayResponseData data = payResponse.getData();

			String result = data.getResult();
			boolean isBuy = false;
			if (result.equals("ok"))
				isBuy = true;
			json = new JsonObject();
			msg = data.getPrice_message();
			errorMsg = data.getError_message();
			json.addProperty("type", payType);
			if (null != msg && !msg.equals(""))
				json.addProperty("data", msg);
			json.addProperty("isbuy", isBuy);
			if (null != errorMsg && !errorMsg.equals(""))
				json.addProperty("errorMsg", errorMsg);
			requestOnPay(json.toString());

		}

	};

	private boolean findAppVersionTo16() {
		boolean hasAppInfo = false;
		int code = 0 ;
		PackageManager pm = getPackageManager();
		try {
			appInfo = pm.getPackageInfo(appPackName, PackageManager.GET_CONFIGURATIONS);

		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			appInfo = null;
		}
		
		if(null == appInfo)
		{
			try {
				appInfo = pm.getPackageInfo(appPackName_mha, PackageManager.GET_CONFIGURATIONS);
				if(null != appInfo)
				{
					 code = appInfo.versionCode;
					if (code >= 500)
						hasAppInfo = true;
					
					appPackName = appPackName_mha;
				}
	
			} catch (NameNotFoundException e) {
				// TODO Auto-generated catch block
			
			}
			
		
			
		}else{
			 code = appInfo.versionCode;
			if (code >= 27)
				hasAppInfo = true;
		}

		if(!hasAppInfo)
		{
			try {
				appInfo = pm.getPackageInfo(appPackName_aso4, PackageManager.GET_CONFIGURATIONS);
				if(null != appInfo)
				{
					appPackName = appPackName_aso4;
					 code = appInfo.versionCode;
						hasAppInfo = true;
				}
	
			} catch (NameNotFoundException e) {
				// TODO Auto-generated catch block
			
			}
		}
		APP_Version = code;
		return hasAppInfo;
	}

	PayListener selectListener = new PayListener() {
		@Override
		public void onResult(PayResponse payResponse) {

			String msg = "";
			JsonObject json;
			json = new JsonObject();
			if (null == payResponse) {
				// isBuy = false;
				json.addProperty("isbuy", false);
				requestOnInquiry(json.toString());
				return;
			}
			if (payResponse.getError() == 701) {
				msg = "";
				json.addProperty("type", payType);
				json.addProperty("data", msg);
				json.addProperty("isbuy", false);
				// json.addProperty("errorMsg", ON_TOKER_LOST_MSG);
				requestOnInquiry(json.toString());
				return;

			}

			PayResponseData data = payResponse.getData();
			boolean isBuy = false;
			String errorMsg = ON_NETWORK_ERROR_MSG;
			if (null != data) {
				isBuy = data.isIs_buy();
				msg = data.getPrice_message();
				errorMsg = data.getBuy_error_message();
			}
			if (payResponse.getError() == -1) {
				msg = ON_TOKER_LOST_MSG;
				json.addProperty("type", payType);
				json.addProperty("data", msg);
				json.addProperty("isbuy", false);
				json.addProperty("errorMsg", ON_NETWORK_ERROR_MSG);
				requestOnInquiry(json.toString());
				return;
			}

			json.addProperty("type", payType);
			json.addProperty("data", msg);
			json.addProperty("isbuy", isBuy);
			json.addProperty("errorMsg", errorMsg);
			requestOnInquiry(json.toString());

		}

	};
	private PackageInfo appInfo = null;
	private Button btn_startRecord;
	private boolean isStartRecord = false;
	private static ClipboardManager cmb;
	private static String BBK_GIONEE_MAIN_NAME;
	private RelativeLayout adRoot;

	public void buySp() {
		PayCenter.buySP(this, UserID, token, GameID, new PayListener() {

			@Override
			public void onResult(PayResponse arg0) {
				// TODO Auto-generated method stub
				PayResponseData data = arg0.getData();
				String msg = data.getBuy_error_message();
				String res = data.getResult();
				JsonObject json = new JsonObject();
				json.addProperty("result", res);
				json.addProperty("data", msg);

			}
		});
	}

	public void selectSpAndCheat(int type) {
		// TODO Auto-generated method stub
		// 请求解锁
		/*
		 * if(type == PAY_CHEAT) PayCenter.inquiryCheat(this, UserID, token,
		 * GameID,mPayListener );
		 */
		if (!appCodeIsBigger160) {

			JsonObject json = new JsonObject();
			json.addProperty("type", payType);
			json.addProperty("data", UPDATA_APP_TOAST);
			json.addProperty("isbuy", false);
			json.addProperty("errorMsg", UPDATA_APP_TOAST);
			requestOnInquiry(json.toString());
			// payListener.onResult(null);
			return;
		}
		switch (type) {
		case SELECT_SP:
			PayCenter.inquirySP(this, UserID, token, GameID, selectListener);
			break;
		case PAY_SP:
			PayCenter.buySP(this, UserID, token, GameID, payListener);
			break;
		case SELECT_COIN:
			PayCenter.inquiryCoinInfo(this, UserID, token, GameID, selectListener);
			break;
		case PAY_COIN:
			PayCenter.buyCoin(this, UserID, token, GameID, payListener);
			break;
		case SELECT_CHEAT:
			PayCenter.inquiryCheat(this, UserID, token, GameID, selectListener);
			break;
		case PAY_CHEAT:
			PayCenter.buyCheat(this, UserID, token, GameID, payListener);
			break;
		case PAY_JOIN:
			PayCenter.startLobby(this, UserID, token, GameID, "client", RoomID, new PayListener() {

				@Override
				public void onResult(PayResponse payResponse) {
					Log.i("HTTPCON", "onResult");
					String msg;
					JsonObject json;
					String errorMsg;
					json = new JsonObject();
					if (null == payResponse) {
						// isBuy = false;
						json.addProperty("isbuy", false);
						requestOnInquiry(json.toString());
						return;
					}

					if (payResponse.getError() == -1) {

						msg = ON_NETWORK_ERROR_MSG;
						json.addProperty("type", payType);
						json.addProperty("data", msg);
						json.addProperty("isbuy", false);
						json.addProperty("errorMsg", ON_NETWORK_ERROR_MSG);
						requestOnPay(json.toString());
						return;
					}
					PayResponseData data = payResponse.getData();
					if (payResponse.getError() == 701 || null == data) {
						msg = "";
						json.addProperty("type", payType);
						json.addProperty("data", msg);
						json.addProperty("isbuy", false);
						// json.addProperty("errorMsg", ON_TOKER_LOST_MSG);
						requestOnInquiry(json.toString());
						return;

					}

					String result = data.getStatus();
					boolean isBuy = false;
					if (result.equals("ok"))
						isBuy = true;
					json = new JsonObject();
					msg = data.getPrice_message();
					errorMsg = data.getError();
					json.addProperty("type", payType);
					if (null != msg && !msg.equals(""))
						json.addProperty("data", msg);
					json.addProperty("isbuy", isBuy);
					if (null != errorMsg && !errorMsg.equals(""))
						json.addProperty("errorMsg", errorMsg);
					requestOnPay(json.toString());

				}

			});
			break;
		case SELECT_JOIN:
			PayCenter.lobbyPlayCheck(this, UserID, token, GameID, "", "", new PayListener() {

				@Override
				public void onResult(PayResponse payResponse) {
					// TODO Auto-generated method stub
					String msg;
					JsonObject json;
					String errorMsg;
					json = new JsonObject();
					if (null == payResponse) {
						// isBuy = false;
						json.addProperty("isbuy", false);
						requestOnInquiry(json.toString());
						return;
					}

					if (payResponse.getError() == -1) {

						msg = ON_NETWORK_ERROR_MSG;
						json.addProperty("type", payType);
						json.addProperty("data", msg);
						json.addProperty("isbuy", false);
						json.addProperty("errorMsg", ON_NETWORK_ERROR_MSG);
						requestOnInquiry(json.toString());
						return;
					}
					PayResponseData data = payResponse.getData();
					if (payResponse.getError() == 701 || null == data) {
						msg = "";
						json.addProperty("type", payType);
						json.addProperty("data", msg);
						json.addProperty("isbuy", false);
						// json.addProperty("errorMsg", ON_TOKER_LOST_MSG);
						requestOnInquiry(json.toString());
						return;

					}

					boolean isBuy = true;

					json = new JsonObject();
					msg = data.getJoin_message();
					errorMsg = data.getError();
					json.addProperty("type", payType);
					if (null != msg && !msg.equals(""))
						json.addProperty("data", msg);
					json.addProperty("isbuy", isBuy);
					if (null != errorMsg && !errorMsg.equals(""))
						json.addProperty("errorMsg", errorMsg);
					requestOnInquiry(json.toString());
				}
			});
			break;
		default:
			break;
		}

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		unregisterReceiver(paayReceiver);
		unregisterReceiver(playTimeReceiver);
		
		super.onDestroy();
	}

	public static void startAPPActivity() {

		Intent intent = new Intent(Intent.ACTION_MAIN);
		//String packageName = "com.join.android.app.mgsim.mha";
		String className = "com.join.mgps.activity.ForumActivity_";
		ComponentName cn = new ComponentName(appPackName, className);
		intent.setComponent(cn);

		JSONObject jsb = new JSONObject();

		try {
			jsb.put("fid", fid);
			jsb.put("name", "");
			jsb.put("icon_src", "");

			jsb.put("users", 0);
			jsb.put("posts", 0);
			jsb.put("add_time", 0);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		intent.putExtra("key_forum_bean", jsb.toString());
		baseActivity.startActivity(intent);
	}

	private void getSystemPaste() {
		if (null == cmb)
			cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
		ClipData clipData = cmb.getPrimaryClip();
		if (null == clipData)
			return;
		int count = clipData.getItemCount();
		String resultString = "";
		for (int i = 0; i < count; ++i) {

			ClipData.Item item = clipData.getItemAt(i);
			CharSequence str = item.coerceToText(this);
			resultString += str.toString();
		}
		if (resultString.isEmpty() || resultString.equals(""))
			return;
		resultString.trim();
		setPasteForCheat(resultString);
	}

	@SuppressLint("NewApi")
	public static String getPaste() {
		handler.sendEmptyMessage(3);
		return "";
	}

	private boolean isFirstReame(String name) {
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
		return sp.getBoolean(name, true);
	}

	private void setFirestReame(String name) {
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
		Editor edit = sp.edit();
		edit.putBoolean(name, false);
		edit.commit();
	}

	public static String getRecordInfo(String path) {
		String data = "";
		if (path == null || path.length() <= 0)
			return data;
		// String pathPrefix = path.substring(0, path.lastIndexOf(".")+1);
		String pathPrefix = path;
		File file = new File(pathPrefix.substring(0, pathPrefix.lastIndexOf("/")));
		if (!file.isDirectory())
			return data;

		File files[] = file.listFiles();
		for (int i = 0; i < files.length - 1; i++) {
			for (int j = i + 1; j < files.length; j++) {
				File temp;
				if (files[i].lastModified() > files[j].lastModified()) {
					temp = files[j];
					files[j] = files[i];
					files[i] = temp;

				}
			}
		}
		for (int i = 0; i < files.length; i++) {
			if (!files[i].isFile() || !files[i].getName().contains("."))
				continue;
			String fileName = files[i].getAbsolutePath();

			fileName = fileName.substring(0, fileName.lastIndexOf("."));
			if (fileName.equals(pathPrefix)) {
				String scount = files[i].getName().substring(files[i].getName().lastIndexOf(".") + 1);
				int count = 0;
				try {
					count = Integer.parseInt(scount);
				} catch (Exception e) {
					count = -1;
					// TODO: handle exception
				}
				if (count != -1) {
					Date date = new Date(files[i].lastModified());
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dateString = formatter.format(date);
					if (count == 0) {
						String buff = files[i].getAbsolutePath() + "," + files[i].getAbsolutePath() + ".png" + ","
								+ dateString + ";";
						buff += data;
						data = buff;
						continue;

					}

					data += files[i].getAbsolutePath() + "," + files[i].getAbsolutePath() + ".png" + "," + dateString;
					data += ";";

				}

			}

		}
		Log.i("loadRecord", data);
		return data;
	}

	public static String modifyRecordInfo(String path, boolean isVBA, boolean isV2) {
		String data = "";
		if (path == null || path.length() <= 0)
			return data;
		// String pathPrefix = path.substring(0, path.lastIndexOf(".")+1);
		String pathPrefix = path;
		File file = new File(pathPrefix.substring(0, pathPrefix.lastIndexOf("/")));
		if (!file.isDirectory())
			return data;

		File files[] = file.listFiles();
		for (int i = 0; i < files.length - 1; i++) {
			for (int j = i + 1; j < files.length; j++) {
				File temp;
				if (files[i].lastModified() > files[j].lastModified()) {
					temp = files[j];
					files[j] = files[i];
					files[i] = temp;
				}
			}
		}
		int nState = 1;
		String strSrcPath = null;
		String strTmpPath = null;
		if (isVBA) {
			pathPrefix += "vba";
			path += "vba";
		}
		if (isV2) {
			pathPrefix += "_v2";
			path += "_v2";
		}
		for (int i = 0; i < files.length; i++) {
			if (!files[i].isFile() || !files[i].getName().contains("."))
				continue;
			String fileName = files[i].getAbsolutePath();

			fileName = fileName.substring(0, fileName.lastIndexOf("."));
			if (fileName.equals(pathPrefix)) {
				String scount = files[i].getName().substring(files[i].getName().lastIndexOf(".") + 1);
				int count = 0;
				try {
					count = Integer.parseInt(scount);
				} catch (Exception e) {
					count = -1;
					// TODO: handle exception
				}
				if (count != -1) {
					Date date = new Date(files[i].lastModified());
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
					String dateString = formatter.format(date);
					if (count == 0) {
						String buff = files[i].getAbsolutePath() + "," + files[i].getAbsolutePath() + ".png" + ","
								+ dateString + ";";
						buff += data;
						data = buff;
						continue;

					}

					int end = fileName.lastIndexOf('/');
					if (strSrcPath == null)
						strSrcPath = new String(fileName.substring(0, end));
					if (strTmpPath == null)
						strTmpPath = new String(fileName + "TmpState");

					File fileTmpPath = new File(fileName + "TmpState");
					if (!fileTmpPath.exists())
						fileTmpPath.mkdirs();

					int start = fileName.lastIndexOf('/');
					String strStateFileTmp = strTmpPath + "/" + fileName.substring(start + 1, path.length()) + "."
							+ nState;
					String strPngFileTmp = strStateFileTmp + ".png";

					String strStateFileSave = fileName + "." + nState;
					String strPngFileSave = strStateFileSave + ".png";

					String strStateFileSrc = files[i].toString();
					String strPngFileSrc = files[i].toString() + ".png";

					long timeState = files[i].lastModified();
					File newStateFile = new File(strStateFileTmp);
					if (files[i].exists()) {
						files[i].renameTo(newStateFile);// rename到不同目录，源目录的文件会被删除
						newStateFile.setLastModified(timeState);
					}

					File filePng = new File(strPngFileSrc);
					long timePng = filePng.lastModified();
					File newFilePng = new File(strPngFileTmp);
					if (filePng.exists()) {
						filePng.renameTo(newFilePng);
						newFilePng.setLastModified(timePng);
					}
					// data += files[i].getAbsolutePath() + "," +
					// files[i].getAbsolutePath() + ".png" + "," + dateString;
					// data += strStateFile + "," + strPngFile + "," +
					// dateString;
					data += strStateFileSave + "," + strPngFileSave + "," + dateString;
					data += ";";

					// nState--;
					nState++;
				}

			}

		}
		// 剪切到源目录
		if (strSrcPath != null && strTmpPath != null)
			copyFolderReserveTime(strTmpPath, strSrcPath);
		// -----------------------------------

		Log.i("loadRecord", data);
		return data;
	}

	public String dealSDPath(String jstring, String appPath) {
		int versionCode = 0;
		PackageManager pm = getPackageManager();
		Log.e("dealSDPath", appPackName);
		try {
			appInfo = pm.getPackageInfo(appPackName, PackageManager.GET_CONFIGURATIONS);

		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
		}
		if (null != appInfo) {
			versionCode = appInfo.versionCode;
		}
		MyJson myJson = null;
		try {
			myJson = new MyJson(jstring);
			if (null != myJson) {
				romPath = myJson.getString(BaseAppConfig.KEY_ROM_PATH, "");
				try {
					if (versionCode < 41) {
						myJson.put(BaseAppConfig.KEY_UGC_PATH, romPath);
						ugcPath = new String(romPath);
					} else {
						int start = romPath.lastIndexOf('/');
						String strRomName = romPath.substring(start + 1, romPath.length());
						myJson.put(BaseAppConfig.KEY_UGC_PATH, appPath + strRomName + "/" + strRomName);
						File file = new File(appPath + strRomName);
						// File file = new
						// File("/storage/sdcard1/Android/data/com.papa91.gba/mgpapa/33/roms/kdygqhdmy");
						if (!file.exists())
							file.mkdirs();
						ugcPath = new String(appPath + strRomName + "/" + strRomName);

						File src = new File(romPath.substring(0, start) + "/PSP");
						File des = new File(appPath + strRomName + "/PSP");
						if (src.exists())
							src.renameTo(des);
					}
				} catch (Exception e) {
					myJson.put(BaseAppConfig.KEY_UGC_PATH, romPath);
					ugcPath = new String(romPath);
					e.printStackTrace();
				}
				// }
				// else {
				// myJson.put(BaseAppConfig.KEY_UGC_PATH, romPath);
				// ugcPath = new String(romPath);
				// }
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Log.e("dealSDPath", myJson.toString());
		return myJson.toString();
	}

	private static void copyFolderReserveTime(String strSrc, String strDes) {
		File file = new File(strSrc);
		if (!file.isDirectory())
			return;

		File files[] = file.listFiles();
		for (int i = 0; i < files.length; i++) {
			String strNewFile = strDes + "/" + files[i].getName();
			long timeFile = files[i].lastModified();
			File newFile = new File(strNewFile);
			files[i].renameTo(newFile);
			newFile.setLastModified(timeFile);
		}
	}

	public static void uploadEfficiencyData() {
		/*
		 * File file = new File(ugcPath + ".prof"); if (file.exists()) { String
		 * profData = ""; BufferedReader reader = null; try { reader = new
		 * BufferedReader(new FileReader(file)); profData = reader.readLine();
		 * Log.e("Efficiency", "profData->" + profData); reader.close(); //
		 * file.delete(); } catch (Exception e) { e.printStackTrace(); }
		 * 
		 * if (aidlService != null) { try { aidlService.plugEfficiency(GameID,
		 * profData, UserID); } catch (RemoteException e) { e.printStackTrace();
		 * } } }
		 */
	}

	@SuppressWarnings("unused")
	public static boolean isPathWriteable(String path) {
		File file = new File(new File(path), "test.txt");
		if (file != null) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (file.exists()) {
				file.delete();
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	public static String getPhoneInfo() {
		/*
		 * String MANUFACTURER = Build.MANUFACTURER; String model =
		 * Build.DEVICE;
		 */
		return "is_android";
	}

	public static int isSettingSystemManage() {
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(baseActivity);
		int num = sp.getInt("BBK_GIONE_NUM_GUIDE", 0);
		Editor edit = sp.edit();
		
		edit.putInt("BBK_GIONE_NUM_GUIDE", ++num);
		edit.commit();
		if(num > 7)
		{
			return 0;
		}
		String MANUFACTURER = Build.MANUFACTURER;
		Log.i("MANUFACTURER",MANUFACTURER);
		if (MANUFACTURER.equals("BBK")) {

			Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
			mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
			List<ResolveInfo> mApps = baseActivity.getPackageManager().queryIntentActivities(mainIntent, 0);
			for (int i = 0; i < mApps.size(); i++) {
				if (mApps.get(i).activityInfo.packageName.equals("com.iqoo.secure")) {
					// do
					systemSettingType = BBK_IQOO;
					BBK_GIONEE_MAIN_NAME = mApps.get(i).activityInfo.name;
					return systemSettingType;
				}
			}

			return 0;
		} else if (MANUFACTURER.equals("GiONEE")||MANUFACTURER.equals("GIONEE")) {

			Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
			mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
			List<ResolveInfo> mApps = baseActivity.getPackageManager().queryIntentActivities(mainIntent, 0);
			for (int i = 0; i < mApps.size(); i++) {
				if (mApps.get(i).activityInfo.packageName.equals("com.gionee.softmanager")) {
					// do
					systemSettingType = GIONEE_SOFTMANAGER;
					BBK_GIONEE_MAIN_NAME = mApps.get(i).activityInfo.name;
					return systemSettingType;
				}
			}

			return 0;
		}else if(MANUFACTURER.equals("OPPO"))
		{
			return 3;
		}else if(MANUFACTURER.equals("vivo"))
		{
			return BBK_IQOO;
		}

		return 0;
	}

	public void startBBK_GOINEE_sysAPP() {
		switch (systemSettingType) {
		case BBK_IQOO:

			ComponentName name = new ComponentName("com.iqoo.secure", BBK_GIONEE_MAIN_NAME);
			Intent intent = new Intent();
			intent.setComponent(name);
			startActivity(intent);
			break;
		case GIONEE_SOFTMANAGER:
			ComponentName name2 = new ComponentName("com.gionee.softmanager", BBK_GIONEE_MAIN_NAME);

			Intent intent2 = new Intent();
			intent2.setComponent(name2);
			startActivity(intent2);
			break;
		default:

			return;

		}

	}

	public static void setBBK_GOINEE_sysAPP() {
		handler.sendEmptyMessage(4);
	}

	public void raseVipToMgsim(int type) {
		ComponentName comp = new ComponentName(appPackName,
				"com.join.mgps.activity.ShareWebActivity_");
		Intent mIntent = new Intent();
		mIntent.setComponent(comp);
		mIntent.setAction(Intent.ACTION_VIEW);
		mIntent.putExtra(PAPA_EMU_INTENT_EXTRA_ACTION_FROM, type + "");
		mIntent.setAction("com.join.mgps.papa.share_webview_raiseVip");
		this.startActivity(mIntent);
	}

	public static void raiseVip(int type) {
		
		if(type == 8){
			StartcomplainMsg("4","0","http://anv3cjapi.papa91.com/member/battle_kick/index","","");
			return;
		}
		
		Message childMsg = handler.obtainMessage();
		childMsg.what = RAISE_VIP;
		childMsg.arg1 = type;
		handler.sendMessage(childMsg);
	}

	public static void setBannerType(int isClose, int type) {
		switch (type) {
		case 0:

			break;

		default:
			break;
		}

	}

	private void creatFrameLayout() {
		if (null == adRoot) {
			adParent = new RelativeLayout(this);
			int width = this.getResources().getDisplayMetrics().widthPixels;
			width = width * 3 / 4;
			FrameLayout.LayoutParams lay = new FrameLayout.LayoutParams(width, 200);
			lay.gravity = Gravity.CENTER_HORIZONTAL;
			adParent.setLayoutParams(lay);

			adRoot = new RelativeLayout(this);
			adRoot.setId(R.id.ad_root);
			RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
			adRoot.setLayoutParams(params);

			TextView text = new TextView(this);
			text.setText("VIP免广告");
			RelativeLayout.LayoutParams lay1 = new RelativeLayout.LayoutParams(-2, -2);
			int anchor = adRoot.getId();
			lay1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, anchor);
			// lay1.width = 200;
			// lay1.addRule(RelativeLayout.CENTER_VERTICAL,anchor);
			// lay1.addRule(RelativeLayout.ALIGN_PARENT_TOP, anchor);

			text.setPadding(20, 0, 20, 0);
			lay1.setMargins(20, 10, 20, 0);
			text.setLayoutParams(lay1);
			text.setBackgroundResource(R.drawable.baidu_ad_sponsor_back);
			text.setTextColor(0xffc5c5c5);
			text.setTextSize(11);

			adParent.addView(adRoot);
			adParent.addView(text);

			text.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					raseVipToMgsim(8);
				}
			});
			mFrameLayout.addView(adParent);

		}
		adParent.setVisibility(View.GONE);
	}

	public void setRootAdViewParentVisible(boolean isVisible) {
		if (null != adParent)
			if (isVisible)
				adParent.setVisibility(View.VISIBLE);
			else
				adParent.setVisibility(View.GONE);

	}

	private RelativeLayout adParent;

	public void initBanner(JSONArray mArray, String appID) {

		/*
		 * if(m_VIP != 0) return; creatFrameLayout(); AD_appId = appID; for (int
		 * i = 0; i < mArray.length(); i++) { try { JSONObject js= (JSONObject)
		 * mArray.get(i);
		 * 
		 * boolean ad_switch = js.getBoolean("ad_switch"); if(ad_switch) {
		 * String ad_id = js.getString("ad_id"); int typeID =
		 * js.getInt("type_id"); BannerInfo info ; if(typeID == CLOSE_AD) info =
		 * new InterstitialADInfo(this, mFrameLayout, ad_id, AD_appId, typeID);
		 * else info = new BannerInfo(this, adRoot, ad_id, AD_appId, typeID);
		 * bannerInfos.add(info); } } catch (JSONException e) { // TODO
		 * Auto-generated catch block e.printStackTrace(); } }
		 */
	}

	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
	void startPrefecture(int p_id) {

		Intent intent = new Intent(Intent.ACTION_MAIN);
	//	String packageName = "com.join.android.app.mgsim";
		String className = "com.join.mgps.activity.ForumActivity_";
		ComponentName cn = new ComponentName(appPackName, className);
		intent.setComponent(cn);

		JSONObject jsb = new JSONObject();

		try {
			jsb.put("fid", p_id);
			jsb.put("name", "");
			jsb.put("icon_src", "");

			jsb.put("users", 0);
			jsb.put("posts", 0);
			jsb.put("add_time", 0);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		intent.putExtra("key_forum_bean", jsb.toString());
		Message mes = new Message();
		mes.what = 0;
		mes.obj = intent;
		// handler.sendMessage(mes);
		// startActivity(intent);
		// intent.putExtra("key_forum_bean", jsb.toString());
		startActivity(intent);
	}
public void startAdActivity(int type,int id)
{ 
	if(type != 0 && id != 0)
	{
		link_type = type+"";
		link_type_val = id+"";
	}

	 Intent intent = new Intent();
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

     intent.setAction("com.wufun.intent.activity.view.action.emuintent");
     intent.addCategory(Intent.CATEGORY_DEFAULT);// 应用过滤条件

    /* dateBean.setLink_type(1);
     dateBean.setJump_type(6);
     dateBean.setLink_type_val("4176672296");pic_remotepic_remote
     dateBean.setCrc_link_type_val("4176672296");
     dateBean.setTpl_type("1");
     */
    MyJson json = new MyJson();
     try {
		json.put("link_type", link_type);
	     json.put("jump_type", jump_type);
	     json.put("link_type_val", link_type_val);
	     json.put("crc_link_type_val", crc_link_type_val);
	     json.put("tpl_type", tpl_type); 
	} catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

     
     
     intent.putExtra("intentDataJson",json.toString());
     this.startActivity(intent);
     if(onAdShwoIsCloseMine)
    	 finish();
	}
public static void complain(int uuid,int self_uuid)
{
	Message compMsg = handler.obtainMessage();
	compMsg.what = COMPLAIN_PLAYER;
	compMsg.arg1 = uuid;
	compMsg.arg2 = self_uuid;
	handler.sendMessage(compMsg);
}

 

private void initSign()
{

	 
	 PackageManager pm = getPackageManager();
		try {
			appInfo = pm.getPackageInfo(appPackName, PackageManager.GET_CONFIGURATIONS);
			if(null != appInfo)
			{
				DEVICE_VERSION = appInfo.versionCode+"";
			}
		} catch (NameNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
	// DEVICE_VERSION = tm.g
	String str = DEVICE_ID + "gzRN53VWRF9BYUXo"+"mg2014";
	Log.d("initSign", str);
	httpKeySign = getMD5(str);
	Log.d("initSign", str);
	final MyJson json = new MyJson();
	try {
		json.put("version", DEVICE_VERSION);
		json.put("deviceid", DEVICE_ID);
		json.put("sign", httpKeySign);
		MyJson mesg = new MyJson();
		JSONArray mesgArray = new JSONArray();
		mesg.put("args", mesgArray);
		json.put("messages",mesg);
	} catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	HttpUtils httpUtils = new HttpUtils();
	httpUtils.sendRequestWithHttpClient(HttpUtils.EXIT_AD_URL,json.toString(), new HttpFinishInterface() {
		
	

		@Override
		public void onRequestSuccess(String args) {
			// TODO Auto-generated method stub
			try {
				 messData = args;
				MyJson json = new MyJson(args);
				JSONObject messages = json.getJSONObject("messages");
				JSONArray data = messages.getJSONArray("data");
				JSONObject imageData = (JSONObject) data.get(0);
				String imageFile =imageData.getString("pic_remote");
				
				
				link_type = imageData.getString("link_type");
				jump_type = imageData.getString("jump_type");
				link_type_val = imageData.getString("link_type_val");
				crc_link_type_val = imageData.getString("crc_link_type_val");
				tpl_type = imageData.getString("tpl_type");
				int adType = imageData.getInt("ad_switch");
				int quitTYpe = imageData.getInt("quit_switch");
				if(adType != 0)
				{
					hasAd = true;
					if(quitTYpe != 0)
					{
						onAdShwoIsCloseMine = true;
					} 
				}
			
				DownLoadFile downLoad = new DownLoadFile();
				File dateDir = Environment.getExternalStorageDirectory();
				String fileDir = dateDir+"/papa91/images/";
				ExitAdImageFilePath = downLoad.downLoad(fileDir, imageFile);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		@Override
		public void onRequestError(String args) {
			// TODO Auto-generated method stub
			
		}
	});
	
}
public String getMD5(String info)
{
	try
	{
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		md5.update(info.getBytes("UTF-8"));
		byte[] encryption = md5.digest();
			
		StringBuffer strBuf = new StringBuffer();
		for (int i = 0; i < encryption.length; i++)
		{
			if (Integer.toHexString(0xff & encryption[i]).length() == 1)
			{
				strBuf.append("0").append(Integer.toHexString(0xff & encryption[i]));
			}
			else
			{
				strBuf.append(Integer.toHexString(0xff & encryption[i]));
			}
		}
			
		return strBuf.toString();
	}
	catch (NoSuchAlgorithmException e)
	{
		return "";
	}
	catch (UnsupportedEncodingException e)
	{
		return "";
	}
}
public static String getExitAdPath()
{
	if(hasAd)
		return ExitAdImageFilePath;
	else
		return "";
}
}
